import 'package:flutter/material.dart';

class BottomNav extends StatefulWidget {
  final int currentKey;
  final setCurrentKey;
  BottomNav({Key key, this.currentKey, this.setCurrentKey}):super(key: key);

  @override
  _BottomNav createState() => _BottomNav();
}

class _BottomNav extends State<BottomNav> {

  List<Map> navIcons = [
    {
      "default": {
        "icon": "lib/assets/images/bottomNavIcons/cat_0.png",
        "color": 0xFFADADAD,
      },
      "current": {
        "icon": "lib/assets/images/bottomNavIcons/cat_1.png",
        "color": 0xffff7f15,
      },
      "name": "广场",
    },
    {
      "default": {
        "icon": "lib/assets/images/bottomNavIcons/dog_0.png",
        "color": 0xFFADADAD,
      },
      "current": {
        "icon": "lib/assets/images/bottomNavIcons/dog_1.png",
        "color": 0xffff7f15,
      },
      "name": "任务榜",
    },
    {
      "default": {
        "icon": "lib/assets/images/bottomNavIcons/rabbit_0.png",
        "color": 0xFFADADAD,
      },
      "current": {
        "icon": "lib/assets/images/bottomNavIcons/rabbit_1.png",
        "color": 0xffff7f15,
      },
      "name": "宠物",
    },
  ];



  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 60.0,
      color: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: navIcons.asMap().keys.map((key) {
          String show = widget.currentKey == key ? "current" : "default";
          return InkWell(
            child: Container(
              padding: EdgeInsets.only(top: 6.0),
              child: Column(
                children: <Widget>[
                  Image.asset(
                    navIcons[key][show]["icon"],
                    width: 30.0,
                    height: 30.0,
                  ),
                  Text(
                    navIcons[key]["name"],
                    style: TextStyle(
                      color: Color(navIcons[key][show]["color"]),
                      fontSize: 12.0,
                      fontWeight: FontWeight.w600,
                    ),
                  )
                ],
              ),
            ),
            onTap: (){
              widget.setCurrentKey(key);
            },
          );
        }).toList(),
      ),
    );
  }
}